package com.cupcorn.lib.display;

import java.util.ArrayList;

import org.andengine.entity.scene.Scene;

import com.cupcorn.lib.game.GameEngine;
import com.cupcorn.lib.game.GameRectangle;
import com.cupcorn.lib.game.element.GameElementRectangle;

public class DisplayRectangle
{
	GameEngine						engine;
	GameElementRectangle			elementRectangle;
	GameElementRectangle[]			gameElementRectangle;
	ArrayList<GameElementRectangle>	listRectangle;
	GameRectangle					rectangle;
	
	boolean							isArray, isArrayList;
	
	public DisplayRectangle(GameEngine engine, GameElementRectangle elementRectangle)
	{
		this.engine = engine;
		this.elementRectangle = elementRectangle;
		isArray = false;
		isArrayList = false;
	}
	
	public DisplayRectangle(GameEngine engine, GameElementRectangle[] gameElementRectangle)
	{
		this.engine = engine;
		this.gameElementRectangle = gameElementRectangle;
		isArray = true;
		isArrayList = false;
	}
	
	public DisplayRectangle(GameEngine engine, ArrayList<GameElementRectangle> listRectangle)
	{
		this.engine = engine;
		this.listRectangle = listRectangle;
		isArray = false;
		isArrayList = true;
	}
	
	public GameRectangle newRectangle(int index)
	{
		return newRectangle(index, engine.getEngine().getScene());
	}
	
	public GameRectangle newRectangle(int index, Scene scene)
	{
		if (isArrayList)
		{
			rectangle =
				new GameRectangle(listRectangle.get(index).x, listRectangle.get(index).y, listRectangle.get(index).width, listRectangle.get(index).height,
					engine.getVertexBufferObjectManager());
			rectangle.setColor(listRectangle.get(index).red, listRectangle.get(index).green, listRectangle.get(index).blue, listRectangle.get(index).alpha);
		}
		else if (isArray)
		{
			rectangle =
				new GameRectangle(gameElementRectangle[index].x, gameElementRectangle[index].y, gameElementRectangle[index].width,
					gameElementRectangle[index].height, engine.getVertexBufferObjectManager());
			rectangle.setColor(gameElementRectangle[index].red, gameElementRectangle[index].green, gameElementRectangle[index].blue,
				gameElementRectangle[index].alpha);
		}
		else
		{
			rectangle =
				new GameRectangle(elementRectangle.x, elementRectangle.y, elementRectangle.width, elementRectangle.height,
					engine.getVertexBufferObjectManager());
			rectangle.setColor(elementRectangle.red, elementRectangle.green, elementRectangle.blue, elementRectangle.alpha);
		}
		scene.attachChild(rectangle);
		return rectangle;
	}
}
